/****** Object:  Stored Procedure dbo.CGO_GameGetList    Script Date: Friday, March 04, 2011 ******/
IF EXISTS ( SELECT  *
            FROM    dbo.sysobjects
            WHERE   id = OBJECT_ID(N'dbo.CGO_GameGetList')
                    AND OBJECTPROPERTY(id, N'IsProcedure') = 1 ) 
  DROP PROCEDURE dbo.CGO_GameGetList
GO


SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

/* -------------------------------------------------------------------------------------
/   GameList 
/  ------------------------------------------------------------------------------------- */
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE dbo.CGO_GameGetList
  @PortalID INT,
  @EventID INT
AS 
  IF @EventID IS NULL
  BEGIN
  	SET @EventID = 0
  END
  
  SELECT  GameID ,
          PortalID ,
          PackageName ,
          Name ,
          Description ,
          ImageURL ,
          ImageType ,
          ImageWidth ,
          ImageHeight ,
          GameTabID ,
          Status ,
          Category ,
          ImageDisplay ,
          CreatedByID ,
          UC.Username AS CreateByUserName ,
          CreatedDate ,
          LastUpdatedID ,
          UU.Username AS LastUpdateUserName ,
          LastUpdateDate
  FROM    dbo.CGO_Game M
          LEFT JOIN dbo.Users UC ON M.CreatedByID = UC.UserID
          LEFT JOIN dbo.Users UU ON M.LastUpdatedID = UU.UserID
  WHERE   --PortalID = @PortalID
          --AND 
          ( @EventID = 0
                OR GameID IN ( SELECT GameID
                               FROM   dbo.CGO_EventGame
                               WHERE  EventID = @EventID
                               AND PortalID = @PortalID )
              )
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

